{% extends "base_generic.html" %}
{% block script %}
<script type="text/javascript">
function generateUrl(name) {
  var sanitizedName = string_to_slug(name);
  $("#url").val(sanitizedName);
}

  var from;
  function addArtist(){
    from = $('#actorsfrom');
    to = $('#actorsto');
    option = $('#actorsfrom option:selected');
    text = option.text();
    value = option.val();
    to.append($("<option></option>").val(value).html(text));
    option.remove();
    writeArtist();
  }

  function removeArtist(){
    from = $('#actorsfrom');
    to = $('#actorsto');
    option = $('#actorsto option:selected');
    text = option.text();
    value = option.val();
    from.append($("<option></option>").val(value).html(text));
    option.remove();
    writeArtist();
  }

  function writeArtist(){
     cast=$('#cast');
     to=$('#actorsto');
     tooptions=$('#actorsto option');
     str='';
     cont=to.children().size();
     for(i=0;i<cont;i++){
       str+=tooptions.eq(i).val();
       if(i<cont-1){
         str+=',';
       }
     }
     cast.val(str);
  }

</script>
{% endblock %}
{% block content %}
	<h1>Film</h1>
<form name="edit-admin" id="edit-admin" method="post" action="{{path}}">
<div class="field">
<label for="originalname">Original name:</label>
<input type="text" name="originalname" id="originalname" value="{{film.originalname}}" onblur="generateUrl($('#originalname').val())" />
</div>
<div class="field">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="{{film.name}}" onblur="generateUrl($('#name').val())" />
</div>
<div class="field">
<label for="url">URLs:</label>
<input type="text" name="url" id="url" value="{{film.url}}" />
</div>
<div class="field">
<label for="year">year</label>
<input type="text" name="year" id="year" value="{{film.year}}" />
</div>
<div class="field">
<label for="genre">Genre:</label>
{% for genre in genres %}
{% if forloop.first %}
<select name="genre" id="genre">
{% endif %}
<option value="{{genre.key}}" {% ifequal genre.name film.genre.name %}selected="selected"{% endifequal %}>{{genre.name}}</option>
{% if forloop.last %}
</select>
{% endif %}
{% endfor %}
</div>
<div class="field">
<label for="director">Director:</label>
{% for director in directors %}
{% if forloop.first %}
<select name="director" id="director">
{% endif %}
<option value="{{director.key}}" {% ifequal director.name film.director.name %}selected="selected"{% endifequal %}>{{director.name}}</option>
{% if forloop.last %}
</select>
{% endif %}
{% endfor %}
</div>
    <div class="field" id="field-actors">
    <label for="cast">Cast:</label>
    <table>
      <tr>
        {% for actor in actors %}
        {% if forloop.first %}
        <td><select size="8" name="actorsfrom" id="actorsfrom">
          {% endif %}
          <option value="{{actor.key}}">{{actor.name}}</option>
          {% if forloop.last %}
          </select>
        </td>
        {% endif %}
        {% endfor %}
        <td>
          <input type="button" name="add" id="add" value=">" onclick="addArtist();return false;" /><br/><input type="button" name="remove" id="remove" value="<" onclick="removeArtist();return false;" />
          <input type="hidden" name="cast" id="cast" value="unchanged" />
        </td>
        <td>
          <select size="8" name="actorsto" id="actorsto">
          {% for personxfilm in personxfilms %}
          <option value="{{personxfilm.person.key}}">{{personxfilm.person.name}}</option>
          {% endfor %}
          </select>
        </td>
      </tr>
    </table>
    </div>

<div style="clear:both" class="field">
<label for="description">Description:</label>
<textarea name="description" rows="5" cols="45" id="description">{{film.description}}</textarea>
</div>
</div><br class="clear" />
<input type="submit" name="save" class="mainbutton" id="publish" value="Save" />
<input type="hidden" name="codenum" id="codenum" value="{{filekey}}" />
<br class="clear" />
</form>
{% endblock %}
